package com.yun.algorithmproblem.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Leetcode624 {

    public static void main(String[] args) {
        Leetcode624 obj=new Leetcode624();
        List<List<Integer>> arrays=new ArrayList<>();
        arrays.add(List.of(-3,-3));
        arrays.add(List.of(-3,-2));
        obj.maxDistance(arrays);
    }


    public int maxDistance(List<List<Integer>> arrays) {
        int[] left=new int[arrays.size()];
        int[] right=new int[arrays.size()];
        int leftMax=Integer.MIN_VALUE,rightMax=Integer.MIN_VALUE;
        int maxDis=0;
        for (int i = 0; i < arrays.size(); i++) {
            left[i]=leftMax;
            List<Integer> list = arrays.get(i);
            leftMax=Math.max(leftMax, list.get(list.size()-1));
        }
        for (int i = arrays.size()-1; i >= 0; i--) {
            right[i]=rightMax;
            List<Integer> list = arrays.get(i);
            rightMax=Math.max(rightMax, list.get(list.size()-1));
        }
        for (int i = 0; i < arrays.size()-1; i++) {
            maxDis=Math.max(maxDis,right[i]-arrays.get(i).get(0));
        }
        for (int i = arrays.size()-1; i >0 ; i--) {
            maxDis=Math.max(maxDis,left[i]-arrays.get(i).get(0));
        }
        return maxDis;
    }
}
